Package com.fsf.news

Class ReflectionTestUtils

java.lang.Object
com.fsf.news.ReflectionTestUtils

public class ReflectionTestUtils extends Object
Utility class for reflection operations.
  • Constructor Details

    • ReflectionTestUtils

      public ReflectionTestUtils()
  • Method Details

    • getField

      public static Field getField(Class<?> clazz, String fieldName)
      Retrieves a Field object from a class or its superclasses.
      Parameters:
      clazz - The class to search for the field
      fieldName - The name of the field to retrieve
      Returns:
      The Field object, or null if not found
    • getValue

      public static Object getValue(Object object, String fieldName)
      Retrieves the value of a field from an object.
      Parameters:
      object - The object containing the field
      fieldName - The name of the field to retrieve
      Returns:
      The value of the field
    • getValue

      public static Object getValue(Class<?> clazz, String fieldName)
      Retrieves the value of a static field from a class.
      Parameters:
      clazz - The class containing the field
      fieldName - The name of the field to retrieve
      Returns:
      The value of the field
    • setValue

      public static void setValue(Object object, String fieldName, Object value)
      Sets the value of a field in an object.
      Parameters:
      object - The object containing the field
      fieldName - The name of the field to set
      value - The new value of the field
    • setValue

      public static void setValue(Class<?> clazz, String fieldName, Object value)
      Sets the value of a static field in a class.
      Parameters:
      clazz - The class containing the field
      fieldName - The name of the field to set
      value - The new value of the field